package com.bulletelc.apollopre.module.main.center.intention.list.fragment;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bulletelc.apollopre.R;
import com.bulletelc.apollopre.entity.IntentionBean;

import java.util.List;

/**
 * Created by Administrator on 2018/5/16.
 */

public class IntentionListAdapter extends BaseAdapter {

    private Context context;
    private List<IntentionBean> intentionBeanList;
    private LayoutInflater inflater;

    public IntentionListAdapter(Context context, List<IntentionBean> list) {
        this.context = context;
        this.intentionBeanList = list;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return intentionBeanList.size();
    }

    @Override
    public Object getItem(int i) {
        return intentionBeanList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        IntentionBean intentionBean = intentionBeanList.get(i);
        ViewHolder viewHolder;
        if (view == null) {
            view = inflater.inflate(R.layout.intention_list_item, viewGroup, false);
            viewHolder = new ViewHolder();
            viewHolder.tvOrder = view.findViewById(R.id.tvOrder);
            viewHolder.tvName = view.findViewById(R.id.tvName);
            viewHolder.tvMobile = view.findViewById(R.id.tvMobile);
            viewHolder.tvDate = view.findViewById(R.id.tvDate);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.tvOrder.setText(context.getString(R.string.intention_order) + intentionBean.getCode());
        viewHolder.tvName.setText(context.getString(R.string.intention_name) + intentionBean.getContact_man());
        viewHolder.tvMobile.setText(context.getString(R.string.intention_mobile) + intentionBean.getContact_phone());
        viewHolder.tvDate.setText(intentionBean.getCreated_at());

        return view;
    }

    class ViewHolder {

        private TextView tvOrder, tvName, tvMobile, tvDate;

    }
}
